PROCEDURE TForm4.TestShlWAPISHUnicodeToUnicode(Sender : TObject);
//Support for function as ordinal 346 under Win 98 SE (with IE 5.0) confirmed !!!
//Support for function as ordinal 346 under NT 4.0 with IE 5.0 confirmed !!!
VAR srcwcharbuf : WideString;
VAR srcstrlen : INTEGER;
VAR destwcharbuf : ARRAY[0..64] OF WideChar;
VAR destbufsize : INTEGER;
VAR apiretval : INTEGER;
VAR errorcode : INTEGER;
VAR newinfoline : STRING;
BEGIN
srcwcharbuf := '';
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
srcwcharbuf := 'Hello copy Unicode to Unicode World !';
srcstrlen := Length(srcwcharbuf);
destbufsize := Length(destwcharbuf);
//Initialize dest buffer with text that ought to be replaced by
//the SHUnicodeToUnicode function call. Necessary to test
//if the function terminates the copied Unicode string with a null character.
//The line also exemplifies how useful the SHAnsiToUnicode function can be.
SHAnsiToUnicode('A text with which the output buffer was previously initialized', destwcharbuf, destbufsize);
newinfoline := 'SHUnicodeToUnicode called with source string "' + srcwcharbuf + '" returned ';
apiretval := SHUnicodeToUnicode(PWChar(srcwcharbuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' dest buffer : "' + destwcharbuf + '"'
ELSE
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !)';
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 23 (too short by 10 character)
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 27;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHUnicodeToUnicode called with source string "' + srcwcharbuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHUnicodeToUnicode(PWChar(srcwcharbuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 1 (too short by 36 characters)
//FillChar(destansibuf, SizeOf(destansibuf), #0);
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 1;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHUnicodeToUnicode called with source string "' + srcwcharbuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHUnicodeToUnicode(PWChar(srcwcharbuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 0
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHUnicodeToUnicode called with source string "' + srcwcharbuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHUnicodeToUnicode(PWChar(srcwcharbuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//No dest buffer (pointer param set to NIL)
//and buffer length parameter set to 0
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHUnicodeToUnicode called with source string "' + srcwcharbuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHUnicodeToUnicode(PWChar(srcwcharbuf), NIL, 0);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
Memo1.Lines.Add('');
END; |